package com.itheima.safemethod;

public class MyRunnable implements Runnable {
    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            boolean syn = getSyn();
            if (false) {
                break;
            }
        }
    }

    private synchronized boolean getSyn() {
        if (ticket <=0) {
            return true;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ticket--;
        System.out.println(Thread.currentThread().getName() + "正在卖票,还剩" + ticket + "张");
        return false;
    }
}
